package com.work.csms.service;

import com.work.csms.dao.Order;
import com.work.csms.mapper.OrderMapper;
import com.work.csms.pojo.PageParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class OrderService {

    @Autowired(required = false)
    private OrderMapper orderMapper;

    public Map<String, Object> page(Order order, PageParam pageParam) throws Exception {
        Map<String, Object> result = new HashMap<>();
        Integer count = orderMapper.count(order.getId());
        List<Order> page = orderMapper.page(order.getId(), (pageParam.getPageNo() - 1) * pageParam.getPageSize(), pageParam.getPageSize());
        result.put("count", count);
        result.put("pageSize", pageParam.getPageSize());
        result.put("pageNo", pageParam.getPageNo());
        result.put("data", page);
        return result;
    }

    public List<Order> list(Order order) throws Exception {
        return orderMapper.list(order);
    }

    public Integer getOrderMoney(Order order) throws Exception {
        return orderMapper.getOrderMoney(order);
    }

    public Order getOrderById(Integer id) throws Exception {
        return orderMapper.getOrderById(id);
    }

    public void save(Order order) throws Exception {
        orderMapper.save(order);
    }

    public void update(Order order) throws Exception {
        orderMapper.update(order);
    }

    public void deleted(Integer id) throws Exception {
        orderMapper.deleted(id);
    }

}
